import win32con
import win32gui
import time

# 找出窗体编号
def window_basic():
    QQWin = win32gui.FindWindow("TXGuiFoundation", "我的iPhone")  # 类名，标题
    CmdWin = win32gui.FindWindow("ConsoleWindowClass", "管理员: C:\windows\system32\cmd.exe")  # 控制CMD窗体
    Wechat = win32gui.FindWindow("WeChatMainWndForPC", "微信")
    while True:
        # 隐藏窗体
        print("hiding")
        win32gui.ShowWindow(Wechat, win32con.SW_HIDE)
        time.sleep(2)

        # 显示窗体
        print("showing")
        win32gui.ShowWindow(Wechat, win32con.SW_SHOWNORMAL)
        time.sleep(2)

        # 窗口最大化
        win32gui.ShowWindow(Wechat, win32con.SW_MAXIMIZE)

        time.sleep(2)

        # 设置最前
        win32gui.SetForegroundWindow(Wechat)

# WindowRect返回窗口矩形的坐标点
def find_window_movetop(cls):
    hwnd = win32gui.FindWindow("WeChatMainWndForPC", "微信")
    win32gui.ShowWindow(hwnd, 5)
    win32gui.SetForegroundWindow(hwnd)
    rect = win32gui.GetWindowRect(hwnd)   # 这获取的是什么？
    time.sleep(0.2)
    return rect

# 获取所有系统中的窗口句柄
def _MyCallback(hwnd, windows):
    temp = []
    temp.append(hex(hwnd))
    temp.append(win32gui.GetClassName(hwnd))
    temp.append(win32gui.GetWindowText(hwnd))
    windows[hwnd] = temp

print(find_window_movetop("WeChatMainWndForPC"))

windows = {}
win32gui.EnumWindows(_MyCallback, windows)
print(windows)